home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-04 | 9.7 KB | 471 lines | [TEXT/ttxt] |
- %%
- %Metaprogramming PostScript: A System for Arbitrary Diagnostic Analysis
- %This text is Copyright 1992 Gregory Koomey. All rights are reserved;
- %nothing herein shall be used without written consent from the author.
-
- %Listing 1
-
- %%begin utility dict definition
- 20 dict dup begin
- /utility exch def %internal identity of dict
- /outfile (Horatio:Programming:Qued/M:quark outfile) (w) file def
-
- %in case of error, the following code closes outfile
- %/*handleerror errordict /handleerror get def
- %errordict begin
- % /handleerror {
- % outfile closefile
- % *handleerror
- % } bind def
- % end %%errordict
- %%end of error handling code
-
- /thesysdict systemdict def %to keep original systemdict available
- /workstring 100 string def
-
- %some useful procedures
- /comment
- {outfile (Comment: ) writestring
- outfile exch writestring
- outfile (\r) writestring} bind def
- /makestring
- {workstring cvs dup length string copy} bind def
- /dostack %inverted destructive stack print
- {outfile (dostack: ) writestring
- count
- {writeobj outfile ( ) writestring}
- repeat
- outfile (\r) writestring} bind def
-
- %%The following are included for the complex compiler model
- /writeobj % depends on the following dictionary definition
- {dup type dup writeobjdict exch known
- {writeobjdict exch get exec} %
- {workstring cvs outfile exch writestring pop} ifelse
- } bind def
- 14 dict dup /writeobjdict exch def
- begin
- /arraytype {xcheck { outfile (-executable-arraytype- ) writestring}
- { outfile (-arraytype- ) writestring}ifelse
- } bind def
- /booleantype {workstring cvs outfile exch writestring
- outfile ( ) writestring} bind def
- /dicttype {pop outfile (-dicttype- ) writestring} bind def
- /filetype {pop outfile (-filetype- ) writestring} bind def
- /fonttype {pop outfile (-fonttype- ) writestring} bind def
- /integertype {workstring cvs outfile exch writestring
- outfile ( ) writestring} bind def
- /marktype {pop outfile (-marktype- ) writestring} bind def
- /nametype {outfile (/) writestring
- workstring cvs outfile exch writestring
- outfile ( ) writestring} bind def
- /nulltype {pop outfile (-nulltype- ) writestring} bind def
- /operatortype {pop outfile (-operatortype- ) writestring} bind def
- /packedarraytype {xcheck {outfile (-executable-packedarraytype- ) writestring}
- {outfile (-packedarraytype- ) writestring} ifelse
- } bind def
- /realtype {workstring cvs outfile exch writestring
- outfile ( ) writestring} bind def
- /savetype {pop outfile (-savetype- ) writestring} bind def
- /stringtype {dup rcheck not
- {pop outfile (\() writestring
- outfile (-string-with-no-read-access- ) writestring
- outfile (\)) writestring
- outfile ( ) writestring}
- {outfile (\() writestring
- outfile exch writestring
- outfile (\)) writestring
- outfile ( ) writestring } ifelse
- } bind def
- end%writeobjdict
-
- /dictdump
- {
- exch writeobj writeobj
- outfile (\r) writestring
- } bind def
-
-
- /writename
- {
- outfile /dummy writestring
- outfile (\r) writestring
- } bind def
- /combineprocs %takes two procs, returns combined proc
- {
- mark
- counttomark 2 add index
- aload pop
- counttomark 1 add index
- aload pop counttomark packedarray cvx
- 4 1 roll pop pop pop
- } bind def
-
- /compile1
- {
- dup
- type dup /packedarraytype ne
- {/arraytype eq}
- {pop true} ifelse
- {
- dup xcheck
- {
- dup rcheck
- {
- exch dup 3 1 roll makestring
- /writename load 1
- 3 2 roll put
- /writename load exch combineprocs
- 2 index 4 1 roll put
- }
- {
- /outfile load
- 3 -1 roll dup 4 1 roll makestring
- /writestring load
- /outfile load
- (\r)
- /writestring load
- 7 -1 roll
- thesysdict /exec get
- 8 packedarray
- cvx
- 3 -1 roll dup 4 2 roll
- put
- } ifelse
-
- }
- {pop pop} ifelse
- }
- {
- dup type /operatortype eq
- {
- /outfile load
- 3 -1 roll dup 4 1 roll makestring
- /writestring load
- /outfile load
- (\r)
- /writestring load
- 7 -1 roll
- 7 packedarray %
- cvx
- 3 -1 roll dup 4 2 roll
- put
- }
- {pop pop}
- ifelse
- }
- ifelse
- } bind def
-
-
- /compile2 {
- numberdict exch get exch
- dup 3 1 roll %copy of key at bottom of stack
- dup dict2 exch known
- {
- dict2 exch get
- combineprocs
- dict2 3 1 roll put
- }
- {
- workstring cvs outfile exch writestring
- outfile ( ... is not known in dict\r) writestring
- pop
- pop
- }
- ifelse
-
- } bind def
-
- %%end of utility dict definition
-
- (end of systemdict listing) comment
- %%beginning of code specifically for duplication of systemdict
- systemdict length dict dup /dict2 exch def%the arbitrary name used here for our dict is /dict2
- systemdict {3 -1 roll dup 4 2 roll put} forall %
- dup
- dup /systemdict exch put %redefine systemdict entry
-
- %two special operation definitions which may or may not be necessary
- %dup
- %/load %offered a key as operand
- % {dup thesysdict exch known
- % {thesysdict exch dup 3 1 roll get
- % type /operatortype ne
- % {load} if
- % }
- % {load} ifelse
- % } bind put
-
- %dup
- %/get %offered a dict and key as operand
- % { exch dup 3 1 roll
- % systemdict eq
- % {thesysdict exch dup 3 1 roll get
- % type /operatortype eq
- % {exch pop}
- % {get} ifelse
- % }
- % {get} ifelse
- % } bind put
-
- %%end of code specifically for duplication of systemdict
-
-
- dup
- {compile1}
- forall
-
- pop
-
- % code to list dict2 in outfile as /name object/type
- (the following is a listing of dict2) comment
- systemdict
- {dictdump}
- forall
- (end of listing of dict2) comment
-
- 6 dict dup /numberdict exch def begin
- /1 {
- dup writeobj outfile ( ) writestring
- } bind def
- /2 {
- 2 copy exch writeobj outfile ( ) writestring
- writeobj outfile ( ) writestring
- } bind def
- /3 {
- 3 copy 3 -1 roll writeobj outfile ( ) writestring
- exch writeobj outfile ( ) writestring
- writeobj outfile ( ) writestring
- } bind def
- /4 {
- 4 copy 4 -1 roll writeobj outfile ( ) writestring
- 3 -1 roll writeobj outfile ( ) writestring
- exch writeobj outfile ( ) writestring
- writeobj outfile ( ) writestring
- } bind def
- /5 {
- 5 copy 5 -1 roll writeobj outfile ( ) writestring
- 4 -1 roll writeobj outfile ( ) writestring
- 3 -1 roll writeobj outfile ( ) writestring
- exch writeobj outfile ( ) writestring
- writeobj outfile ( ) writestring
- } bind def
- /6 {
- 6 copy 6 -1 roll writeobj outfile ( ) writestring
- 5 -1 roll writeobj outfile ( ) writestring
- 4 -1 roll writeobj outfile ( ) writestring
- 3 -1 roll writeobj outfile ( ) writestring
- exch writeobj outfile ( ) writestring
- writeobj outfile ( ) writestring
- } bind def
-
- end%numberdict
-
- %Listing 2
- 165 dict dup
- /dict3 exch def
- begin
- %math ops
- /add /2 def
- /div /2 def
- /idiv /2 def
- /mod /2 def
- /mul /2 def
- /sub /2 def
- /abs /1 def
- /neg /1 def
- /ceiling /1 def
- /floor /1 def
- /round /1 def
- /truncate /1 def
- /sqrt /1 def
- /atan /2 def
- /cos /1 def
- /sin /1 def
- /exp /2 def
- /ln /1 def
- /log /1 def
- /srand /1 def
- %array ops
- /array /1 def
- /length /1 def
- /get /2 def
- /put /3 def
- /getinterval /3 def
- /putinterval /3 def
- /astore /1 def
- /aload /1 def
- /copy /2 def
- /forall /2 def
- %packedarray ops
- /packedarray /1 def
- /setpacking /1 def
- %Dict ops
- /dict /1 def
- /maxlength /1 def
- /begin /1 def
- /load /1 def
- /known /2 def
- /where /1 def
- /copy /2 def
- /dictstack /1 def
- %string ops
- /string /1 def
- /anchorsearch /2 def
- /search /2 def
- /token /1 def
- %boolean ops
- /eq /2 def
- /ne /2 def
- /ge /2 def
- /gt /2 def
- /le /2 def
- /lt /2 def
- /and /2 def
- /not /1 def
- /or /2 def
- /xor /2 def
- /bitshift /2 def
- %control ops
- /exec /1 def
- /if /2 def
- /ifelse /3 def
- /for /4 def
- /repeat /2 def
- /loop /1 def
- /stopped /1 def
- /execstack /1 def
- %type ops
- /type /1 def
- /cvlit /1 def
- /cvx /1 def
- /xcheck /1 def
- /executeonly /1 def
- /noaccess /1 def
- /readonly /1 def
- /rcheck /1 def
- /wcheck /1 def
- /cvi /1 def
- /cvn /1 def
- /cvr /1 def
- /cvrs /3 def
- /cvs /2 def
- %file ops
- /file /2 def
- /closefile /1 def
- /read /1 def
- /write /2 def
- /readhexstring /2 def
- /writehexstring /2 def
- /readstring /2 def
- %/writestring /2 def %might duplicate output
- /readline /2 def
- /token /1 def
- /bytesavailable /1 def
- /flushfile /1 def
- /resetfile /1 def
- /status /1 def
- /run /1 def
- /print /1 def %might duplicate output, depending on setup...
- %VM ops
- /restore /1 def
- %gstate ops
- /setlinewidth /1 def
- /setlinecap /1 def
- /setlinejoin /1 def
- /setmiterlimit /1 def
- /setdash /2 def
- /setflat /1 def
- /setgray /1 def
- /sethsbcolor /3 def
- /setrgbcolor /3 def
- /setscreen /3 def
- /settransfer /1 def
- %coord system and matrix ops
- /identmatrix /1 def
- /defaultmatrix /1 def
- /currentmatrix /1 def
- /setmatrix /1 def
- /translate /2 def %sometimes /3
- /scale /2 def %sometimes /3
- /rotate /1 def
- /concat /1 def
- /concatmatrix /3 def
- /transform /2 def%sometimes /3
- /dtransform /2 def%sometimes /3
- /itransform /2 def%sometimes /3
- /idtransform /2 def%sometimes /3
- /invertmatrix /2 def
- %path construction
- /moveto /2 def
- /rmoveto /2 def
- /lineto /2 def
- /rlineto /2 def
- /arc /5 def
- /arcn /5 def
- /arcto /5 def
- /curveto /6 def
- /rcurveto /6 def
- /charpath /2 def
- /pathforall /4 def
- %paint
- /image /5 def
- /imagemask /5 def
- %device setup and output
- /banddevice /4 def
- /framedevice /4 def
- /renderbands /1 def
- %character and font
- /definefont /2 def
- /findfont /1 def
- /scalefont /2 def
- /makefont /2 def
- /setfont /1 def
- /show /1 def
- /ashow /3 def
- /widthshow /4 def
- /awidthshow /6 def
- /kshow /2 def
- /stringwidth /1 def
- %font cache ops
- /setcachedevice /6 def
- /setcharwidth /2 def
- /setcachelimit /1 def
- /setcacheparams /3 def
- %stack manipulation ops
- /pop /1 def
- /exch /2 def
- /dup /1 def
- /copy /2 def
- /index /1 def
- /roll /2 def
-
- %needs to be at end of definition of dict
-
- /bind /1 def
- /def /2 def
- end %dict is in utility dict under dict3
- %
- (end of dict3 definition\r) comment
-
-
- dict3 %procedure requires that dict to be modified is in utility as dict2
- {compile2}
- forall
-
- (this is the end of the dict redefinition...\r) comment
-
- %Systemdict Finish
- dict2 begin
- userdict begin
-
- (the following is a listing of dict2, after n-ary stuff added) comment
- systemdict
- {dictdump}
- forall
- (end of listing of dict2, after n-ary stuff added) comment
-
- (this is the beginning of redefined environment...\r) comment
- %%
-